﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Windows.Controls.Ribbon;
using Southridge.Data;
using System.Collections.ObjectModel;
using Southridge.View;
using Microsoft.Windows.Controls;
using Southridge.Business;
using System.Xml.Linq;

namespace Southridge
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : RibbonWindow
    {
        protected MainViewModel ViewModel; 


        public Window1()
        {             
           this.DataContext = 
            this.ViewModel = new MainViewModel( new MessageBoxViewLogger() );
            InitializeComponent();
            
            ViewManager vm = ViewManager.Create(this.MainContent, true, this.ViewModel );
            vm.Add(this.searchView, Views.Search);

            
        }

      


#if SQLCE 
        public void SaveListings( ListingCollection list)
        {
            XElement main = new XElement("Listings"); 
            foreach ( Listing li in list ) 
            {
                try
                {
                    XElement xe = new XElement("Listing",
                       new XAttribute("MLS", li.MLS), 
                       new XAttribute("Title", li.Title) ,
                       new XAttribute("Description", li.Description),
                       new XAttribute("BedroomCount", li.BedroomCount),
                       new XAttribute("BathroomCount", li.BathroomCount),
                       new XAttribute("Address1", li.Address.Address1),
                       new XAttribute("Address2", ( li.Address.Address2 == null) ?  "" : li.Address.Address2 ),
                       new XAttribute("City", li.Address.City),
                       new XAttribute("ZipCode", li.Address.ZipCode),
                       new XAttribute("Price", li.Price),
                       new XAttribute("Year", li.Year),
                        new XAttribute("SquareFootage", li.SquareFootage),
                         new XAttribute("DatePosted", li.DatePosted),
                         new XAttribute("CreationDate", li.CreationDate),
                         new XAttribute("LastEditDate", li.LastEditDate),
                         new XAttribute("ClientRating", li.ClientRating),
                          new XAttribute("HasPhotos", li.HasPhotos),
                          new XAttribute("Appt", li.HasAppt),
                 
                        new XAttribute("NeighborhoodId", li.Neighborhood.Id)
                        
                       );

                    main.Add(xe);  

                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);  
                } 
               
            }        
        } 
#endif 

         
        



          
    }

   
}
